/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package sistemperpustakaan.actionlistener;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyVetoException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JInternalFrame;
import sistemperpustakaan.view.FrmMain;
import sistemperpustakaan.view.buku.FrmPenerbitBukuView;

/**
 *
 * @author Eko Aprianto
 */
public class ViewPenerbitBukuActionListener implements ActionListener {
    FrmMain main;

    public ViewPenerbitBukuActionListener(FrmMain main) {
        this.main = main;
    }

    public boolean isExists(){
        boolean result = false;
        JInternalFrame[] iFrame = main.getDesktopPane().getAllFrames();
        for(int i=0;i < iFrame.length; i++){
            if(iFrame[i].equals(main.getPenerbitBukuView())){
                result = true; break;
            }
        }
        return result;
    }

    public void actionPerformed(ActionEvent e) {
        if(isExists()){
            try {
                main.getPenerbitBukuView().setSelected(true);
            } catch (PropertyVetoException ex) {
            }
         }else{
            try {
                main.setPenerbitBukuView(new FrmPenerbitBukuView(main));
                main.getDesktopPane().add(main.getPenerbitBukuView());
                main.getPenerbitBukuView().setVisible(true);
                main.getPenerbitBukuView().setMaximum(true);
            } catch (PropertyVetoException ex) {
                Logger.getLogger(ViewPenerbitBukuActionListener.class.getName()).log(Level.SEVERE, null, ex);
            }
         }
    }

}
